﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;

namespace MvcApplication1.Models
{
    public partial class Topic
    {
        public bool EsValido
        {
            get { return (GetViolacionesDeReglas().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetViolacionesDeReglas()
        {
            if (string.IsNullOrWhiteSpace(this._Cuerpo))
                yield return new RuleViolation("Cuerpo Requerido", "_Cuerpo");
            if (string.IsNullOrWhiteSpace(this._Tema))
                yield return new RuleViolation("Tema Requerido", "_Tema");
        }


        partial void OnValidate(ChangeAction action)
        {
            if (!EsValido)
                throw new ApplicationException("Rule violations prevent saving");
        }
    }
}